Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

array3

array3

(T 
type
)
:
hashable
 is
[Private constructor]
array(length0, length1, length2) -- three-dimensional immutable array

array provides three-dimensional immutable arrays. These are actually
one-dimensional immutable arrays with an additional access function with
three index parameters.
Precondition
pre
  safety: length0 ≥ 0
  safety: length1 ≥ 0
  safety: length2 ≥ 0
  safety: length0 *? length1 *? length2 >=? 0

Type Parameters

Fields

length0
 i64
length1
 i64
length2
 i64
the underlying one dimensional array

multidimensional indices are mapped to one dimensional indices as follows:

[x,y,z] -> [(x * length1 + y) * length2 + z]

resulting in the order:

arr[0,0,0], arr[0,0,1], arr[0,0,2], ...,
arr[0,1,0], arr[0,1,1], arr[0,1,2], ...,
arr[1,0,0], arr[1,0,1], arr[1,0,2], ...

Functions

 => 
String
[Redefinition of  Any.as_string]
create a string representation of this array including all the string
representations of its contents, separated by ',' and enclosed in '['
and ']'. Arrays in inner dimensions are grouped using '[' and ']'.

redefines:

(R 
type
, F 
type
: Typed_Function R, f F)
 => 
R
[Inherited from  Any]
dynamic_apply -- apply `f.call` to `Any.this`'s dynamic type and value

This can be used to perform operation on values depending on their dynamic
type.

Here is an example that takes a `Sequence Any` that may contain boxed values
of types `i32` and `f64`. We can now write a feature `get_f64` that extracts
these values converted to `f64` and build a function `sum` that sums them up
as follows:


 => 
Type
[Inherited from  Any]
Get the dynamic type of this instance. For value instances `x`, this is
equal to `type_of x`, but for `x` with a `ref` type `x.dynamic_type` gives
the actual runtime type, while `type_of x` results in the static
compile-time type.

There is no dynamic type of a type instance since this would result in an
endless hierarchy of types. So for Type values, dynamic_type is redefined
to just return Type.type.
get a list of tuples indices and elements in this array
(I 
type
:
integer, i0 I, i1 I, i2 I)
 => 
T
indices range in first dimension
indices range in second dimension
indices range in third dimension
 => 
String
[Inherited from  Any]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.

Type Features

 => 
String
[Inherited from  Type]
string representation of this type to be used for debugging.

result has the form "<name>", but this might change in the future

redefines:

 => 
Type
[Inherited from  Type]
There is no dynamic type of a type instance since this would result in an
endless hierarchy of types, so dynamic_type is redefined to just return
Type.type here.

Note: Typechecking is undecidable when 'type' is a type, Mark B. Reinhold, 1989
see: https://dspace.mit.edu/bitstream/handle/1721.1/149366/MIT-LCS-TR-458.pdf?sequence=6

redefines:

equality of two array3s is true iff `a` and `b` have the same dimensions and for all
`i in indices0`, `j in indices1` and `k in indices 2` we have `a[i][j][k] = b[i][j][k]`.

For performance, this will compare the length of the arrays first.

This is defined only if T : property.equatable, it will result in a compile-time panic
if this is not the case.
create hash code for this array3.

This should satisfy the following condition:

(T.equality a b) : (T.hash_code a = T.hash_code b)

This will result in a compile-time `panic` in case T : property.hashable does not hold.

The algorithm used here is a variation of [XXXHash](https://xxhash.com) as used in
[Python's tuple](https://github.com/python/cpython/blob/849a80ec412c36bbca5d400a7db5645b8cf54f1f/Objects/tupleobject.c#L305):

we start with a constant `hash_prime1`
for each value:
we take its hash code * `hash_prime2` and add it
then we rotate by `hash_rotate`
and multiply by `hash_prime3`
(T 
type
)
 => 
bool
[Inherited from  Type]
Is this type assignable to a type parameter with constraint `T`?

The result of this is a compile-time constant that can be used to specialize
code for a particular type.


it is most useful in conjunction with preconditions or `if` statements as in


or

NOT implemented, calling this fails at compile time

There is no natural total ordering for three-dimensional arrays
 => 
String
[Inherited from  Type]
name of this type, including type parameters, e.g. 'option (list i32)'.
(I 
type
:
integer, length0 I, length1 I, length2 I, init Function array3.type.T I I I)
 => 
array3 array3.type.T
array(length0, length1, length2) -- three-dimensional immutable array

array provides three-dimensional immutable arrays. These are actually
one-dimensional immutable arrays with an additional access function with
three index parameters.
 => 
String
[Inherited from  Type]
convenience prefix operator to create a string from a value.

This permits usage of `$` as a prefix operator in a similar way both
inside and outside of constant strings: $x and "$x" will produce the
same string.

NYI: Redefinition allows the type feature to be distinguished from its normal counterpart, see #3913

redefines:

 => 
Type
[Inherited from  Any]
Get a type as a value.

This is a feature with the effect equivalent to Fuzion's `expr.type` call tail.
It is recommended to use `expr.type` and not `expr.type_value`.

`type_value` is here to show how this can be implemented and to illustrate the
difference to `dynamic_type`.

Applicable universe features

These are features in universe, that have an argument with a type constraint that matches this features type and can therefore be used with it.
(T 
type
:
property.equatable, a T, b T)
 => 
bool
equals -- feature that compares two values using the equality relation
defined in their type
(T 
type
:
property.hashable, a T)
 => 
u64
hash of a value
(T 
type
:
property.equatable, a T, b T)
 => 
bool
infix = -- infix operation as shorthand for 'equals'
(T 
type
:
property.equatable, a T, b T)
 => 
bool
infix = -- infix operation as shorthand for 'equals'
is `a` contained in `Set` `s`?

This should usually be called using type inference as in

is `a` not contained in `Set` `s`?

This should usually be called using type inference as in

(T 
type
:
property.equatable, a T, b T)
 => 
bool
infix ≟ -- infix operation as shorthand for 'equals'
memoize `f`.
wraps f so that f will only be called once for every unique input.

The term "memoization" was coined by Donald Michie in 1968 and
is derived from the Latin word "memorandum" ("to be remembered"),
usually truncated as "memo" in American English, and thus carries
the meaning of "turning a function into something to be remembered".
https://en.wikipedia.org/wiki/Memoization

example:

0.099dev (GIT hash 02118e9cbed77f3897084a4a507da3f11ac8881e)
last changed: 2026-09-02